package com.ruoyi.partybuilding.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.partybuilding.domain.MallPoints;
import lombok.extern.slf4j.Slf4j;
import lombok.var;
import org.springframework.data.util.NullableUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.Date;


@Slf4j
@Service
public class MallPointsServiceImpl extends BaseServiceImpl<MallPoints>{
    public MallPoints newPoints(long userId, double points, String source, String remark){
        var topPoints=topPoints(userId);
        var topTotal=topPoints==null?0:topPoints.getTotal();
        var mp=new MallPoints();
        mp.setSource(source);
        mp.setRemark(remark);
        mp.setPoints(points);
        mp.totalSetBy(topTotal);
        mp.setUserId(userId);
        mp.setUpdateTime(new Date());
        return  mp;
    }
    public MallPoints topPoints(long userId){
        var newPoints= equeryable().where(p->p.eq(MallPoints::getUserId,userId)).orderByDesc(p->p.column(MallPoints::getId)).firstOrNull();
        return newPoints;
    }

}
